﻿using System;
using System.Net;
using System.IO;

namespace LiveatEdu.dao
{
    public class ConnectionFTP
    {   
        /*
         * Esse método não funciona se tiver proxy na rede, tem que mandar autenticado
         */

        public  string GetFile(Uri FileName, string UserName, string Password)
        {
            WebClient Client = null;
            StreamReader Reader = null;
            try
            {
                Client = new WebClient();
                Client.Credentials = new NetworkCredential(UserName, Password); 
                Reader = new StreamReader(Client.OpenRead(FileName));
                string Contents = Reader.ReadToEnd();
                Reader.Close();
                return Contents;
            }
            catch
            {
             return "";
            }
            finally
            {
                if (Reader != null)
                {
                    Reader.Close();
                }
            }
        }

   } 
}
